package com.example.financecollegeorderdish.ui

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.drake.channel.sendEvent
import com.example.financecollegeorderdish.R
import com.example.financecollegeorderdish.databinding.ActivityVitaminInputBinding
import com.example.financecollegeorderdish.db.bean.VitaminBean
import com.quyunshuo.androidbaseframemvvm.base.mvvm.vm.EmptyViewModel
import com.wuhao.lib_base.mvvm.v.BaseActivity
import com.wuhao.lib_common.utils.NotNullHelper
import io.reactivex.rxjava3.core.Observable
import java.util.concurrent.TimeUnit

class VitaminInputActivity : BaseActivity<ActivityVitaminInputBinding,EmptyViewModel>() {
    override val mViewModel: EmptyViewModel
        get() = EmptyViewModel()
    override fun createVB(): ActivityVitaminInputBinding =ActivityVitaminInputBinding.inflate(layoutInflater)

    override fun initObserve() {
    }

    override fun initRequestData() {
    }

    override fun ActivityVitaminInputBinding.initView() {
        mBinding.btnOk.setOnClickListener {
            getVitaminData()
            newRx.add(
                Observable.timer(500, TimeUnit.MILLISECONDS)
                .subscribe {
                    finish()
                })
        }
        mBinding.btnCancel.setOnClickListener { finish() }

    }

    private fun getVitaminData() {
        sendEvent(
            VitaminBean(
                getContent(mBinding.vitaminB1.text.toString()),
                getContent(mBinding.vitaminB2.text.toString()),
                getContent(mBinding.vitaminB3.text.toString()),
                getContent(mBinding.vitaminB5.text.toString()),
                getContent(mBinding.vitaminB6.text.toString()),
                getContent(mBinding.vitaminB7.text.toString()),
                getContent(mBinding.vitaminB9.text.toString()),
                getContent(mBinding.vitaminB12.text.toString()),
                getContent(mBinding.vitaminC.text.toString()),
                getContent(mBinding.vitaminA.text.toString()),
                getContent(mBinding.vitaminD.text.toString()),
                getContent(mBinding.vitaminE.text.toString()),
                getContent(mBinding.vitaminK.text.toString()),
            )
        )

    }

    fun getContent(inputStr: String): String =
        if (NotNullHelper.notEmpty(inputStr)) {
            inputStr
        } else {
            ""
        }
}